<?php

namespace Biz\service\Album;


use Biz\model\Album\AlbumCategoryModel;
use Biz\model\Album\AlbumCategoryRelateModel;
use Biz\model\Album\AlbumListModel;
use Doraemon\service\statSign\Basic as basicStatSign;
use Doraemon\tools\BlockType;

class AlbumCategoryRelateService
{

    /**
     * @param $categoryId
     * @param $page
     * @param $pageSize
     * @return array
     */
    public static function getFindMoreList($categoryId, $page, $pageSize): array
    {
        $result = [];
        $result['is_over'] = 1;
        $result['list'] = [];
        //根据分类查询清单id集合
        $where = [
            'status' => AlbumListModel::STATS_LIST_PUBLIC_SHOW_MAP,
            'score[>=]' => AlbumListModel::SCORE_GOOD,
            'ORDER' => ['publish_time' => 'DESC'],
            'LIMIT' => [($page - 1) * $pageSize, $pageSize],
        ];
        if ($categoryId > 0) {
            $albumIds = AlbumCategoryRelateModel::selectByWhere([
                'category_id' => $categoryId,
                'status' => AlbumCategoryRelateModel::STATUS_NORMAL,
            ], 'album_id');
            $where['album_id'] = array_unique($albumIds);
        }

        //查询清单数据
        $list = AlbumListModel::selectByWhere($where);
        $result['is_over'] = count($list) < $pageSize ? 1 : 0;
        if ($list && is_array($list)) {
            $categoryName = AlbumCategoryModel::getByWhere('*', ['id' => $categoryId]);
            $formatInfo = FormatAlbumService::_formatAlbumList($list, FormatAlbumService::SQUARE_LIST);
            foreach ($formatInfo as $key => $val) {
                $val['statSign'] = basicStatSign::genStatSign(basicStatSign::MODULE_GOOD_ALBUM_PAGE_ALBUM_LIST, [
                    basicStatSign::EXTEND_KEY_OBJ_TYPE => BlockType::TYPE_WIKI_ALBUM,
                    basicStatSign::EXTEND_KEY_OBJ_ID => $val['album_info']['album_id'],
                    basicStatSign::EXTEND_KEY_INDEX => $key,
                    basicStatSign::EXTEND_KEY_POS => 'bottom',
                ], [
                    'tab' => $categoryName['category_name'] ?? '全部',
                ]);
                $result['list'][] = $val;
            }

        }

        return $result;
    }

}